Skip to content

fix(SUPPORT-14907): improve error logging when page token lookup fails#125

Closed
devin-ai-integration[bot] wants to merge 3 commits intomasterfrom
devin/SUPPORT-14907-1768230793-fix-pagination-future-timestamps
Closed

fix(SUPPORT-14907): improve error logging when page token lookup fails#125
devin-ai-integration[bot] wants to merge 3 commits intomasterfrom
devin/SUPPORT-14907-1768230793-fix-pagination-future-timestamps

Conversation

@devin-ai-integration
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot commented Jan 12, 2026

Summary

Fixes visibility into Facebook Pages API v2 returning 403 errors for post_insights requests by improving error logging during page token lookup.

Root cause: The swallow-exceptions macro was silently catching all exceptions during page token lookup, causing the component to fall back to user token without any indication of what went wrong. This led to confusing 403 Forbidden errors when the user token lacked page-level permissions.

Changes in query.clj:

  • Replace swallow-exceptions macro with try-with-warning that logs errors
  • Add detailed error message when both /me/accounts and page details API fail
  • Only attempt page details API if accounts list lookup didn't find token
  • Improve logging to help diagnose token permission issues

Now when page token lookup fails, you'll see messages like:

  • "Warning: fetching accounts list for page X failed: 403 Forbidden"
  • "Page token failed for X: both /me/accounts and page details API failed. The user token will be used but may lack permissions for insights queries."

Review & Testing Checklist for Human

  • Test with failing configuration: Run a Facebook Pages API v2 extraction that was previously failing with 403 errors on post_insights
  • Check new error logging: Verify that token lookup failures now produce visible warning messages in logs
  • Verify no regression: Run a working Facebook Pages extraction to ensure normal operation is unaffected

Recommended test plan:

  1. Deploy branch to test environment using runtime.tag configuration
  2. Run the customer's failing Facebook Pages configuration
  3. Check logs for "Warning: fetching accounts list" or "Page token failed" messages
  4. Verify the error messages help diagnose the actual permission issue

Notes

Important: This fix improves visibility into token lookup failures but does not automatically resolve permission issues. If the user's token lacks the required permissions (e.g., pages_read_engagement, read_insights), the extraction will still fail - but now with clear error messages explaining why.

https://keboola.atlassian.net/browse/SUPPORT-14907

Link to Devin run: https://app.devin.ai/sessions/17f4b3f016a7446f8f4e6bbf7a8c8e14
Requested by: Zora Jelínková

Release Notes

Justification, description

Improve error logging when page token lookup fails in Facebook Pages API v2, making it easier to diagnose 403 Forbidden errors.

Plans for Customer Communication

N/A

Impact Analysis

Low risk - logging-only change:

  • Token logging changes only add visibility, don't change functional behavior
  • Falls back to user token same as before, just with better error messages

Deployment Plan

N/A

Rollback Plan

N/A

Post-Release Support Plan

N/A

Fixes Facebook Pages API v2 returning 400/403 errors for post_insights
requests using insights.since(now).metric(...).

Root cause: Facebook returns paging.next URLs with Unix timestamps
pointing to the future, which fail with error: '(#100) since param is
not valid. Metrics data is available for the last 2 years.'

Changes:
- Add parse-unix-ts helper to parse 10-digit Unix timestamps
- Add extract-url-param helper to extract query params from URLs
- Add remove-url-param helper to remove query params from URLs
- Add handle-future-timestamps to process pagination URLs:
  - If both since and until are in future -> skip (end of data)
  - If only until is in future -> remove it, API uses 'now' implicitly
- Update get-next-page-url to use handle-future-timestamps

This fix is similar to the one applied in component-meta PR #19 for
Instagram insights.

Co-Authored-By: Zora Jelínková <zora.jelinkova@keboola.com>
@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Previously, exceptions during page token lookup were silently swallowed,
causing the component to fall back to user token without any indication
of what went wrong. This led to confusing 403 Forbidden errors when the
user token lacked permissions for page insights.

Changes:
- Replace swallow-exceptions macro with try-with-warning that logs errors
- Add detailed error message when both /me/accounts and page details fail
- Only attempt page details API if accounts list lookup didn't find token
- Improve logging to help diagnose token permission issues

Co-Authored-By: Zora Jelínková <zora.jelinkova@keboola.com>
@devin-ai-integration devin-ai-integration Bot changed the title fix(SUPPORT-14907): handle future timestamps in pagination URLs fix(SUPPORT-14907): handle future timestamps and improve token error logging Jan 13, 2026
Per user request, removing the future timestamp handling code as it
was not the correct fix for SUPPORT-14907. The actual issue is related
to page token lookup failures, which is addressed by the token logging
fix in query.clj.

Co-Authored-By: Zora Jelínková <zora.jelinkova@keboola.com>
@devin-ai-integration devin-ai-integration Bot changed the title fix(SUPPORT-14907): handle future timestamps and improve token error logging fix(SUPPORT-14907): improve error logging when page token lookup fails Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants